<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0053)https://bugs.eclipse.org/bugs/attachment.cgi?id=56601 -->
<HTML><HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META content="MSHTML 6.00.2900.3020" name=GENERATOR>
<TITLE>Using JSPs and Servlets to render Charts and set Preferences</TITLE></HEAD>
<BODY>
<H1><A name=10>Using JSPs and Servlets to render Charts and set 
Preferences</A></H1>
<UL>
  <LI><STRONG><A 
  href="https://bugs.eclipse.org/bugs/attachment.cgi?id=56601#00">Configuring 
  Eclipse to launch a Tomcat server</A></STRONG> 
  <LI><STRONG><A 
  href="https://bugs.eclipse.org/bugs/attachment.cgi?id=56601#01">Creating a 
  Dynamic Web Project</A></STRONG> 
  <LI><STRONG><A 
  href="https://bugs.eclipse.org/bugs/attachment.cgi?id=56601#02">Developing 
  your own chart pages via JSPs and Servlets</A></STRONG> </LI></UL>
<HR>

<H3><A name=00>Configuring Eclipse to 
launch a Tomcat server</A></H3>
<P>The following components 
are required to run Tomcat from within Eclipse</P>
<TABLE cellSpacing=0 cellPadding=0 border=1>
  <TBODY>
  <TR height=30>
    <TD vAlign=center>
      <P><STRONG>Component</STRONG></P></TD>
    <TD>
      <P><STRONG>Location in 
      the local environment</STRONG></P></TD></TR>
  <TR>
    <TD width=202>BIRT 2.2, 
      Report Designer Full Eclipse Install (includes Eclipse 3.3, BIRT 2.2 and 
      the required dependent plugins) </TD>
    <TD width=493>C:\Eclipse_3.3</TD></TR>
  <TR>
    <TD>Sun Java 
      JDK1.5.0_06</TD>
    <TD>C:\jdk1.5.0_06</TD></TR>
  <TR>
    <TD>Tomcat 
    5.5.x</TD>
    <TD>C:\Tomcat</TD></TR></TBODY></TABLE>
<P><STRONG>Configuring Tomcat 
in the Eclipse Servers view </STRONG></P>
<P>
<OL>
  <LI>Launch Eclipse. 
  <LI>Open the J2EE Perspective, then the Servers view. 
  <LI>Right-click from within the Servers view to bring up the context menu, 
  then select New &gt; Server. 
  <LI>Select the application server you have installed, in this example, Apache 
  Tomcat v5.5 Server, then click Next. 
  <LI>Browse to the directory where you installed the Apache Tomcat v5.5 Server, 
  and make sure the Installed JRE is at least Java version 5 (Tomcat 5.5.x 
  requires this.). Then click Finish. </LI></OL>
<P></P>
<P><STRONG>Starting Tomcat 
from Eclipse</STRONG></P>
<P>
<OL>
  <LI>Go to the Servers view and bring up the context menu from the server you 
  just created. 
  <LI>Select Start. 
  <LI>The status in the Servers view should now say Started. Refer to the 
  Console view if any problems occur. </LI></OL>
<P><A 
href="https://bugs.eclipse.org/bugs/attachment.cgi?id=56601#10">TOP</A></P>
<HR>

<H3><A name=01>Creating a Dynamic Web 
Project</A></H3>
<OL>
  <P>
  <LI>Select the context menu from within the Project Explorer view and select 
  New &gt; Project. Select Web &gt; Dynamic Web Project, then click Next. 

  <P></P>
  <P></P>
  <LI>The Dynamic Web Project wizard appears. Give the project a name, for 
  example, BirtChartExample, and make sure the target runtime is the Tomcat 
  server you just created. Click Next. 
  <P></P>
  <P></P>
  <LI>On the Project Facets page, select the BIRT Reporting Runtime Component 
  checkbox. This adds the BIRT runtime libraries to the dynamic web application. 
  Also make sure the Dynamic Web Module, and the Java project facet is checked. 
  Click Next. On the Web Module page click Finish. 
  <P></P>
  <P></P>
  <LI>Now the JSPs, servlet, Java files and some additional BIRT libraries need 
  to be imported into the project. <BR>These additional libraries need to be 
  added to the web application and are available from the BIRT All-in-One Report 
  Designer download or the standalone Chart Engine download: </LI></OL>
<BLOCKQUOTE>
  <UL>
    <LI>org.eclipse.birt.chart.device.extension_2.2.0vXXXXXXXX-XXXX.jar 

    <LI>org.eclipse.birt.chart.device.svg_2.2.0vXXXXXXXX-XXXX.jar 
    <LI>org.eclipse.birt.chart.engine.extension_2.2.0vXXXXXXXX-XXXX.jar 
    </LI></UL></BLOCKQUOTE>
<OL start=5>
  <P>
  <LI>To add these libraries, expand the WebContent folder under the web 
  application just created, and select the lib folder under the WEB-INF folder. 
  Right-click the lib folder and select Import..., then General &gt; File 
  System. Click Next. 
  <P></P>Browse to the 
  eclipse/plugins directory where the jar files listed above have been unpacked 
  to. Select these jar files and import them into the web application's 
  WebContent/WEB-INF/lib folder. Click Finish. (Note: A bug in the Project 
  Explorer view prevents the files in the lib folder from being displayed. To 
  double-check you imported them, switch to the Navigator view.) </LI></OL>
<P><A name=01><STRONG>Importing the JSPs, servlet and Java files</STRONG></A></P>
<OL>
  <LI>
  <P>From the Project Explorer view, select the WebContent folder at the top 
  level of the web application and right-click it to import the JSPs. Import the 
  JSPs to the WebContent folder from the file system as you did above. 
  Alternately, you can copy the JSPs, chartImage.jsp, control.jsp, and 
  UserPreference.jsp, to the WebContent folder. </P>
  <LI>
  <P>From the Project Explorer view select the Java Resources: src folder, bring 
  up the context menu and select New &gt; Package. Create a package called 
  org.eclipse.birt.chart.examples.api.preference. Now import or copy into this 
  package these Java source files; </P>
  <UL>
    <LI>PreferenceServlet.java 
    <LI>ChartModels.java 
    <LI>LabelStyleProcessor.java </LI></UL>
  <P>from the 
  org.eclipse.birt.chart.examples/src/org/eclipse/birt/chart/examples/api/preference 
  folder. </P></LI></OL>
<P><STRONG>Edit the 
web.xml</STRONG></P>
<P>Edit the web.xml file under 
the WebContent/WEB-INF folder to add the servlet mapping. This text should be 
added after the &lt;-welcome-file-list&gt; and before the closing 
&lt;web-app&gt; tag.</P>
<BLOCKQUOTE>
  <P>&lt;servlet&gt;<BR>&lt;servlet-name&gt;PreferenceServlet&lt;/servlet-name&gt;<BR>&lt;servlet-class&gt;org.eclipse.birt.chart.examples.api.preference.PreferenceServlet&lt;/servlet-class&gt;<BR>&lt;/servlet&gt;<BR><BR>&lt;servlet-mapping&gt;<BR>&lt;servlet-name&gt;PreferenceServlet&lt;/servlet-name&gt;<BR>&lt;url-pattern&gt;/PreferenceServlet&lt;/url-pattern&gt;<BR>&lt;/servlet-mapping&gt;</P></BLOCKQUOTE>
<P><STRONG>Running the 
JSPs</STRONG></P>
<P>
<OL>
  <LI>From the Project Explorer view select the control.jsp file, and select Run 
  As &gt; Run On Server from the context menu. 
  <LI>In the Define a New Server page, select Choose an existing server, 
  ensuring that the Tomcat server you set up earlier is selected. Check the Set 
  server as project default checkbox, then click Next. 
  <LI>In the Add and Remove Projects page, the Web project you are working with 
  should be in the Configured Projects side. If it is not, add it to this side. 
  Click Next. Do not check the Update context root for your Web module and click 
  Finish. The page should appear, allowing for selection of font, size, style 
  and color of the bar graph which appears when the Submit button is pushed. 
  </LI></OL>
<P></P>
<P><A href="https://bugs.eclipse.org/bugs/attachment.cgi?id=56601#10">TOP</A></P>
<HR>

<H3><A name=02>Developing your own 
chart pages via JSPs and Servlets</A></H3>
<P>To generate a dynamic, 
revisable chart in your web pages, the required components include a JSP page, a 
Servlet and a chart model.</P>
<P><STRONG>JSPs</STRONG></P>
<P>The JSP pages allow the 
user to set the characteristics of the rendered chart by passing parameters to 
the PreferenceServlet. </P>
<P>1. Set the action for the 
form to call the Servlet. 
<BLOCKQUOTE>&lt;form action="PreferenceServlet" method="POST"&gt; 
</BLOCKQUOTE><BR>2. 
Assign values to the selection or input components 
<BLOCKQUOTE>&lt;option value="value"&gt;XXX&lt;/option&gt; </BLOCKQUOTE>
<P></P>
<P><STRONG>Servlet</STRONG></P>
<P>1. Set the rendering device 
in the constructor</P>
<BLOCKQUOTE>PluginSettings 
  ps = PluginSettings.instance( ); <BR>IDeviceRenderer idr = 
  ps.getDevice("dv.SWING" ); </BLOCKQUOTE>
<P>2. The doGet() 
method</P>
<UL>
  <LI>Create a chart 
  model 
  <LI>Modify the chart model 
  according to the values from JSP 
  <LI>Set the output content 
  type, in this case to a JPEG 
  <LI>Output the chart 
  image </LI></UL>
<P>3. Chart image 
rendering</P>
<UL>
  <LI>Create a buffered 
  image 
  <LI>Build, then render a 
  chart in the buffered image 
  <LI>Output the chart 
  image </LI></UL>
<P><STRONG>Chart 
Model</STRONG></P>
<P>The ChartModel.java class 
is the same class used in the other chart examples plugins.</P>
<P><A href="https://bugs.eclipse.org/bugs/attachment.cgi?id=56601#10">TOP</A></P></BODY></HTML>
